﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace GKQC.Common
{
    /// <summary>
    /// 成品料号解析
    /// </summary>
    public class ProductCode
    {
        /// <summary>
        /// 特殊料號處理: 如HE450V101J45P014ZCGRJ  20位料號後面加了J,不符合料號規則
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string DealSpecialPn(string pn)
        {
            if (string.IsNullOrWhiteSpace(pn)) return pn;

            if (pn == "HE450V101J45P014ZCGRJ")
                return "HE450V101J45P014ZCGR";
            else if (pn == "HE450V101J45P014S00RJ")
                return "HE450V101J45P014S00R";
            else if (pn.Length > 3 && pn.Length < 20)
            {
                int i = 0;
                if (int.TryParse(pn.Substring(2, 1), out i))
                    return pn.PadRight(20, '_');
                else
                    return pn.PadRight(21, '_');
            }
            else return pn;
        }

        /// <summary>
        /// 1 获取料号中的系列：(0, 2) (0, 3)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetSeriesCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(0, 2);
                else if (pn.Length == 21)
                    code = pn.Substring(0, 3);
            }
            return code;
        }

        /// <summary>
        /// 2 获取料号中的电压代码：(2, 3)(3, 3)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetVoltageCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(2, 3);
                else if (pn.Length == 21)
                    code = pn.Substring(3, 3);
            }
            return code;
        }

        /// <summary>
        /// 3 获取料号中的容量范围代码：(5, 1)(6, 1)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetCapRateCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(5, 1);
                else if (pn.Length >= 21)
                    code = pn.Substring(6, 1);
                else if(pn.Length>6 && pn.Length<20)
                    code = pn.Substring(5, 1);
            }
            return code;
        }


        /// <summary>
        /// 4 获取料号中的容量代码：(6, 3)(7, 3);
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetCapCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(6, 3);
                else if (pn.Length == 21)
                    code = pn.Substring(7, 3);
            }
            return code;
        }

        /// <summary>
        /// 5 获取料号中的产品直径代码：(9, 1) ：(10, 1)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetDCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(9, 1);
                else if (pn.Length == 21)
                    code = pn.Substring(10, 1);
            }
            return code;
        }

        /// <summary>
        ///6  获取料号中的产品高度代码：(10, 2) ：(11, 2)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetLCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(10, 2);
                else if (pn.Length == 21)
                    code = pn.Substring(11, 2);
            }
            return code;
        }

        /// <summary>
        ///7  获取料号中的特殊要求代码：(12, 1) ：(13, 1)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetSpecialCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(12, 1);
                else if (pn.Length == 21)
                    code = pn.Substring(13, 1);
            }
            return code;
        }

        /// <summary>
        ///8  获取料号中的客户代号：(13, 3) ：(14, 3)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetCustomerCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(13, 3);
                else if (pn.Length == 21)
                    code = pn.Substring(14, 3);
            }
            return code;
        }

        /// <summary>
        ///9  获取料号中的加工方式或引脚类型：(16, 3) ：(17, 3)
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetMakeCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(16, 3);
                else if (pn.Length == 21)
                    code = pn.Substring(17, 3);
            }
            return code;
        }

        /// <summary>
        ///10  获取料号中的标识区分代号：(19, 1) ：(20, 1)
        ///R代表:非車載產品且符合最新的環保要求. 
        ///J代表:緯創客戶產品出海外工廠(巴西)且符合最新的環保要求. 
        ///A代表:車載產品且符合最新的環保要求. 
        ///V代表:台達客戶符合470VAC測試要求且符合最新的環保要求.
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static string GetFlagCode(string pn)
        {
            pn = DealSpecialPn(pn);
            string code = string.Empty;
            if (!string.IsNullOrWhiteSpace(pn))
            {
                if (pn.Length == 20)
                    code = pn.Substring(19, 1);
                else if (pn.Length == 21)
                    code = pn.Substring(20, 1);
            }
            return code;
        }

        /// <summary>
        /// 獲取成品料號裡的電壓
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetVoltage(string pn)
        {
            double voltage = 0;

            string code = GetVoltageCode(pn);
            if (string.IsNullOrWhiteSpace(code) || code.Length != 3) return voltage;

            switch (code)
            {
                case "2R5":
                    voltage = 2.5;
                    break;
                case "004":
                    voltage = 4.0;
                    break;
                case "006":
                    voltage = 6.3;
                    break;
                case "7R5":
                    voltage = 7.5;
                    break;
                case "010":
                    voltage = 10;
                    break;
                case "016":
                    voltage = 16;
                    break;
                case "025":
                    voltage = 25;
                    break;
                case "028":
                    voltage = 28;
                    break;
                case "035":
                    voltage = 35;
                    break;
                case "050":
                    voltage = 50;
                    break;
                case "063":
                    voltage = 63;
                    break;
                case "080":
                    voltage = 80;
                    break;
                case "100":
                    voltage = 100;
                    break;
                case "160":
                    voltage = 160;
                    break;
                case "180":
                    voltage = 180;
                    break;
                case "200":
                    voltage = 200;
                    break;
                case "250":
                    voltage = 250;
                    break;
                case "315":
                    voltage = 315;
                    break;
                case "330":
                    voltage = 330;
                    break;
                case "350":
                    voltage = 350;
                    break;
                case "400":
                    voltage = 400;
                    break;
                case "420":
                    voltage = 420;
                    break;
                case "450":
                    voltage = 450;
                    break;
                case "460":
                    voltage = 460;
                    break;
                case "500":
                    voltage = 500;
                    break;
                default:
                    break;
            }

            if(voltage == 0)
            {
                string s = code.Replace("R",".");
                double.TryParse(code, out voltage);
            }

            return voltage;
        }

        /// <summary>
        /// 获取料号中的容量范围(%)
        /// </summary>
        /// <param name="pn">成品料號</param>
        /// <param name="capRateMin">範圍百分比下限</param>
        /// <param name="capRateMax">範圍百分比上限</param>
        /// <returns></returns>
        public static void GetCapRate(string pn,out double capRateMin,out double capRateMax)
        {
            capRateMin = -20; capRateMax = 20;
            string code = GetCapRateCode(pn);
            if (string.IsNullOrWhiteSpace(code) || code.Length != 1) return;
            switch (code)
            {
                case "A":
                    capRateMin = 0;
                    capRateMax = 20;
                    break;
                case "B":
                    capRateMin = 10;
                    capRateMax = 30;
                    break;
                case "C":
                    capRateMin = -5;
                    capRateMax = 15;
                    break;
                case "D":
                    capRateMin = -5;
                    capRateMax = 20;
                    break;
                case "E":
                    capRateMin = -15;
                    capRateMax = 20;
                    break;
                case "F":
                    capRateMin = -10;
                    capRateMax = -30;
                    break;
                case "G":
                    capRateMin = -20;
                    capRateMax = 0;
                    break;
                case "H":
                    capRateMin = -5;
                    capRateMax = 10;
                    break;
                case "I":
                    capRateMin = -30;
                    capRateMax = 20;
                    break;
                case "J":
                    capRateMin = -5;
                    capRateMax = 5;
                    break;
                case "K":
                    capRateMin = -10;
                    capRateMax = 10;
                    break;
                case "M":
                    capRateMin = -20;
                    capRateMax = 20;
                    break;
                case "N":
                    capRateMin = 10;
                    capRateMax = 25;
                    break;
                case "Q":
                    capRateMin = -10;
                    capRateMax = 30;
                    break;
                case "R":
                    capRateMin = 0;
                    capRateMax = 50;
                    break;
                case "S":
                    capRateMin = 0;
                    capRateMax = 40;
                    break;
                case "T":
                    capRateMin = -10;
                    capRateMax = 50;
                    break;
                case "V":
                    capRateMin = -10;
                    capRateMax = 20;
                    break;
                case "P":
                    capRateMin = 5;
                    capRateMax = 20;
                    break;
                case "L":
                    capRateMin = -25;
                    capRateMax = 20;
                    break;
                case "X":
                    capRateMin = -20;
                    capRateMax = 100;
                    break;
                case "Y":
                    capRateMin = -6.5;
                    capRateMax = 20;
                    break;
                default:
                    break;
            }

        }

        /// <summary>
        /// 获取料号中的容量范围,不是百分比
        /// </summary>
        /// <param name="pn">成品料號</param>
        /// <param name="capMin">範圍下限</param>
        /// <param name="capMax">範圍上限</param>
        /// <returns></returns>
        public static void GetCapRange(string pn, out double capMin, out double capMax)
        {
            double capRateMin;
            double capRateMax;
            GetCapRate(pn, out capRateMin, out capRateMax);
            double cap = GetCap(pn);
            capMin = Math.Round(cap * (1+capRateMin/100),2);
            capMax = Math.Round(cap * (1+capRateMax/100),2);
        }

        /// <summary>
        /// 獲取成品料號裡的容量
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetCap(string pn)
        {
            double cap = 0;
            double capTemp = 0;

            string code = GetCapCode(pn);
            if (string.IsNullOrWhiteSpace(code) || code.Length!=3) return cap;
            string s = string.Empty;
            if(code == "G52")
            {
                cap = 1650;
            }
            else if (code == "A32")
            {
                cap = 1030;
            }
            else if (code == "H63")
            {
                cap = 17600;
            }
            else if (code.Contains("R"))
            {
                s = code.Replace("R", ".");
                double.TryParse(s, out cap);
            }
            else if (double.TryParse(code, out capTemp))
            {
                string s1 = code.Substring(0, 2);
                string s2 = code.Substring(2, 1);
                int n = 0;
                if(double.TryParse(s1, out cap) && int.TryParse(s2,out n))
                {
                    cap = cap * Math.Pow(10, n);
                }
            }

            return cap;
        }

        /// <summary>
        /// 獲取成品料號裡的產品直徑
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetD(string pn)
        {
            double d = 0;

            string code = GetDCode(pn);
            if (string.IsNullOrWhiteSpace(code) || code.Length != 1) return d;

            d = GetDbyCode(code);

            return d;
        }

        public static double GetDbyCode(string code)
        {
            double d = 0;

            switch (code)
            {
                case "A":
                    d = 5.2;
                    break;
                case "B":
                    d = 3;
                    break;
                case "C":
                    d = 4;
                    break;
                case "D":
                    d = 5;
                    break;
                case "E":
                    d = 6.3;
                    break;
                case "F":
                    d = 8;
                    break;
                case "G":
                    d = 10;
                    break;
                case "H":
                    d = 12;
                    break;
                case "I":
                    d = 13;
                    break;
                case "J":
                    d = 16;
                    break;
                case "K":
                    d = 18;
                    break;
                case "L":
                    d = 20;
                    break;
                case "M":
                    d = 22;
                    break;
                case "N":
                    d = 25;
                    break;
                case "O":
                    d = 30;
                    break;
                case "P":
                    d = 35;
                    break;
                case "Q":
                    d = 40;
                    break;
                case "R":
                    d = 51;
                    break;
                case "S":
                    d = 64;
                    break;
                case "T":
                    d = 76;
                    break;
                case "U":
                    d = 90;
                    break;
                case "V":
                    d = 6.5;
                    break;
                case "W":
                    d = 42;
                    break;
                case "X":
                    d = 12.5;
                    break;
                case "Y":
                    d = 14.5;
                    break;
                case "Z":
                    d = 25.4;
                    break;
                case "1":
                    d = 14;
                    break;
                case "2":
                    d = 15.5;
                    break;
                case "3":
                    d = 21;
                    break;
                case "4":
                    d = 33;
                    break;
                case "7":
                    d = 7.5;
                    break;
                case "8":
                    d = 45;
                    break;
                default:
                    break;
            }

            return d;
        }

        /// <summary>
        /// 獲取成品料號裡的產品高度
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static double GetL(string pn)
        {
            double l = 0;

            string code = GetLCode(pn);
            if (string.IsNullOrWhiteSpace(code) || code.Length != 2) return l;
            if (double.TryParse(code, out l))
                return l;

            double firstValue = GetLFirstValue(code.Substring(0, 1));
            double secondValue = GetLSecondValue(code.Substring(1, 1));
            double t1, t2;
            if (!double.TryParse(code.Substring(0, 1), out t1) && double.TryParse(code.Substring(1, 1), out t2))
                l = firstValue*10 + secondValue;
            else
                l = firstValue + secondValue;
            //l = GetLFirstValue(code.Substring(0, 1)) + GetLSecondValue(code.Substring(1, 1));

            return l;
        }

        /// <summary>
        /// 獲取成品料號中高度代碼第一位字母的對應值
        /// </summary>
        /// <param name="firstCode"></param>
        /// <returns></returns>
        public static double GetLSecondValue(string firstCode)
        {
            double s = 0;

            if (string.IsNullOrWhiteSpace(firstCode) && firstCode.Length != 1)
                return s;

            if (double.TryParse(firstCode, out s))
                return s;

            switch (firstCode)
            {
                case "A":
                    s = 0.4;
                    break;
                case "B":
                    s = 0.5;
                    break;
                case "C":
                    s = 0.6;
                    break;
                case "D":
                    s = 0.7;
                    break;
                case "E":
                    s = 0.8;
                    break;
                case "F":
                    s = 0.9;
                    break;
                case "G":
                    s = 0.1;
                    break;
                case "H":
                    s = 0.2;
                    break;
                case "I":
                    s = 0.3;
                    break;
                default:
                    break;
            }

            return s;
        }
        /// <summary>
        /// 獲取成品料號中高度代碼第二位字母的對應值
        /// </summary>
        /// <param name="secondCode"></param>
        /// <returns></returns>
        public static double GetLFirstValue(string secondCode)
        {
            double s = 0;

            if (string.IsNullOrWhiteSpace(secondCode) && secondCode.Length != 1)
                return s;

            if (double.TryParse(secondCode, out s))
                return s;

            switch (secondCode)
            {
                case "A":
                    s = 10;
                    break;
                case "B":
                    s = 11;
                    break;
                case "C":
                    s = 12;
                    break;
                case "D":
                    s = 13;
                    break;
                case "E":
                    s = 14;
                    break;
                case "F":
                    s = 15;
                    break;
                case "G":
                    s = 16;
                    break;
                case "H":
                    s = 17;
                    break;
                case "I":
                    s = 18;
                    break;
                case "J":
                    s = 19;
                    break;
                case "K":
                    s = 20;
                    break;
                case "L":
                    s = 35;
                    break;
                case "M":
                    s = 22;
                    break;
                case "N":
                    s = 31;
                    break;
                case "P":
                    s = 24;
                    break;
                case "Q":
                    s = 21;
                    break;
                case "S":
                    s = 23;
                    break;
                case "R":
                    s = 32;
                    break;
                case "U":
                    s = 27;
                    break;
                default:
                    break;
            }

            return s;
        }

        /// <summary>
        /// 獲取成品料號中的腳距
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        public static void GetP(string pn,out double P, out double C)
        {
            P = C =0;

            string makeCode = GetMakeCode(pn);
            if (string.IsNullOrWhiteSpace(makeCode) || makeCode.Length != 3)
                return;

            switch(makeCode)
            {
                case "YL0":
                    C = 6.6;
                    break;
                case "YS0":
                    C = 5.4;
                    P = 11.8;
                    break;
                case "YSS":
                    C = 5.4;
                    break;
                case "T00":
                    C = 5.8;
                    break;
                case "TS0":
                    C = 4.0;
                    break;
                case "PCS":
                    C = 5.5;
                    break;
                case "PCY":
                    C = 5.8;
                    break;
                case "PSY":
                    C = 4.0;
                    break;
                case "YSC":
                    C = 5.3;
                    break;
                case "GS0":
                    C = 6.2;
                    break;
                case "PLY":
                    C = 6.0;
                    break;
                case "YLC":
                    C = 7.0;
                    break;
                default:
                    if (makeCode.StartsWith("P") || makeCode.StartsWith("R")
                        || makeCode.StartsWith("I") || makeCode.StartsWith("B"))
                        P = GetMakeTypeValue(makeCode);
                    else C = GetMakeTypeValue(makeCode);

                    if (makeCode.StartsWith("N"))
                            P = 2.0;
                    else if (makeCode.StartsWith("E"))
                        P = 2.5;
                    else if (makeCode.StartsWith("F"))
                        P = 5.0;
                    else if (makeCode.StartsWith("A"))
                        P = 2.5;
                    break;
            }

        }

        /// <summary>
        /// 獲取加工方式中的腳距或腳長
        /// </summary>
        /// <returns></returns>
        public static double GetMakeTypeValue(string makeCode)
        {
            double p = 0;

            if (string.IsNullOrEmpty(makeCode) || makeCode.Length != 3)
                return p;

            if (double.TryParse(makeCode.Substring(1, 2), out p))
                return p / 10;

            string s1 = makeCode.Substring(1, 1);
            string s2 = makeCode.Substring(2, 1);
            double p1 = 0;
            double p2 = 0;
            switch(s1)
            {
                case "A":
                    p1 = 10;
                    break;
                case "B":
                    p1 = 11;
                    break;
                case "C":
                    p1 = 12;
                    break;
                case "D":
                    p1 = 13;
                    break;
                case "E":
                    p1 = 14;
                    break;
                case "F":
                    p1 = 15;
                    break;
                case "G":
                    p1 = 16;
                    break;
                case "H":
                    p1 = 17;
                    break;
                case "I":
                    p1 = 18;
                    break;
                case "J":
                    p1 = 19;
                    break;
                case "K":
                    p1 = 20;
                    break;
                default:
                    break;
            }

            switch(s2)
            {
                case "A":
                    p2 = 0.4;
                    break;
                case "B":
                    p2 = 0.5;
                    break;
                case "C":
                    p2 = 0.6;
                    break;
                case "D":
                    p2 = 0.7;
                    break;
                case "E":
                    p2 = 0.8;
                    break;
                case "F":
                    p2 = 0.9;
                    break;
                case "G":
                    p2 = 0.1;
                    break;
                case "H":
                    p2 = 0.2;
                    break;
                case "I":
                    p2 = 0.3;
                    break;
                default:
                    break;
            }

            p = p1 + p2;


            return p;
        }

        public static string GetSize(string pn)
        {
            return GetD(pn).ToString() + "*" + GetL(pn).ToString();
        }

        public static string GetSpec(string pn,bool withUnit)
        {
            return GetCap(pn).ToString() + (withUnit ? "μF/" : "/")
                + GetVoltage(pn).ToString()
                + (withUnit ? "V" : string.Empty)
                ;
        }

        public static int GetLcTime(string pn)
        {
            int lcTime = 2;

            //todo: LC充電時間

            return lcTime;
        }

        public static double GetLMax(string pn, string customerCode)
        {
            double lMax = 0;
            double l = GetL(pn);
            if (string.IsNullOrWhiteSpace(pn)) return lMax;
            if (pn.Length < 20) return lMax;

            double a = 0;
            if (GetSpecialCode(pn) == "T")
                a = 0.5;

            if (customerCode == "0020")//根茂
                a = 0;
            double b = 0;
            if (l >= 16) b = 2;
            else b = 1;

            lMax = l + a + b;
            return lMax;
        }

        public static double GetLMax(string pn)
        {
            double lMax = 0;
            double l = GetL(pn);
            if (string.IsNullOrWhiteSpace(pn)) return lMax;
            if (pn.Length <20) return lMax;

            double a = 0;
            if(GetSpecialCode(pn) == "T")
                a = 0.5;
            double b = 0;
            if (l >= 16) b = 2;
            else b = 1;

            lMax = l + a + b;
            return lMax;
        }

        public static double GetDMax(string pn, string customerCode)
        {
            double D = GetD(pn);
            if(D>=35) return D + 1;
            else return D + 0.5;
        }

        public static double GetDMax(double D, string customerCode)
        {
            if (D >= 35) return D + 1;
            else return D + 0.5;
        }

        public static double GetDMax(string series,double D)
        {
            if(seriesOxList.Contains(series))
                return D + 1;
            else
            {
                if (D >= 35) return D + 1;
                else return D + 0.5;
            }
        }

        /// <summary>
        /// 牛角系列
        /// </summary>
        static List<string> seriesOxList = new List<string>()
        { "LX", "LXB", "LXA", "LZ", "HZ", "MZ", "TZ", "AZ", "AU", "LM", "LG", "LP", "LS", "LV", "LW", "HP" };


        public static bool IsVchip(string series)
        {
            bool flag = false;
            if (string.IsNullOrWhiteSpace(series)) return flag;

            switch(series)
            {
                case "SPA": case "SPB": case "SVA":  case "SVB":  case "SVV":  case "SVG":  case "SVT":  
                case "EA":  case "EC":  case "EL":  case "EH":  case "ET":  case "EP":  case "PC":  case "PL":  
                case "VA":  case "VC":  case "VL":  case "VH":  case "VT":  case "VP":  case "PV":  case "PH":  

                case "CS": case "CH": case "CK":  case "CN":  case "CD":  case "CG":  case "CL":  case "CKL":  
                case "CDL":  case "CGL":  case "CGS":  case "CGV":  case "CTS":  case "CTV":  case "CDS": case "CLL":
                    flag = true;
                    break;
                default:
                    break;
            }

            return flag;
        }

        /// <summary>
        /// 突波电压,设定电流1.0A
        /// </summary>
        /// <param name="series">系列</param>
        /// <param name="voltage">电压</param>
        /// <returns></returns>
        public static double GetTuboVoltage(string series, double voltage)
        {
            if ((IsVchip(series)) && voltage == 460) return 580;
            else if (IsVchip(series)) return voltage * 1.15;
            else if (voltage == 4) return 5;
            else if (voltage == 6.3) return 8;
            else if (voltage == 10) return 13;
            else if (voltage == 16) return 20;
            else if (voltage == 25) return 32;
            else if (voltage == 35) return 44;
            else if (voltage == 50) return 63;
            else if (voltage == 63) return 79;
            else if (voltage == 80) return 100;
            else if (voltage == 100) return 125;
            else if (voltage == 160) return 200;
            else if (voltage == 180) return 220;
            else if (voltage == 200) return 250;
            else if (voltage == 250) return 300;
            else if (voltage == 315) return 365;
            else if (voltage == 350) return 400;
            else if (voltage == 400) return 450;
            else if (voltage == 420) return 480;
            else if (voltage == 450) return 500;
            else if (voltage == 460) return 550;
            else if (voltage == 500) return 550;
            else return 0;
        }

        /// <summary>
        /// 获取盖板厚度(作废)  todo: 盖板厚度  还有一个参数没处理
        /// </summary>
        /// <param name="D">本体直径</param>
        /// <returns></returns>
        public static double GetCoverThickness(double D)
        {
            double t = 0;
            
            switch(D)
            {
                case 4:
                    t = 0.5;
                    break;
                case 5:
                    t = 0.4;
                    break;
                case 6.3:
                    t = 0.5;
                    break;
                case 8:
                    t = 0.6;
                    break;
                case 8.2:
                    t = 0.55;
                    break;
                case 10:
                    t = 0.6;
                    break;
                case 10.2:
                    t = 0.55;
                    break;
                case 12.5:
                    t = 0.75;
                    break;
                case 16:
                    t = 1;
                    break;
                default:
                    break;
            }

            return t;
        }

        /// <summary>
        /// 获取CAP标准值要保留的小数位数
        /// </summary>
        /// <param name="cap"></param>
        /// <returns></returns>
        public static int GetCapStandardNum(double cap)
        {
            int num = 3;
            if (cap < 1)
                num = 3;
            else if (cap >= 1 && cap <= 10)
                cap = 2;
            else if (cap > 10 && cap < 100)
                num = 1;
            else if (cap >= 100)
                num = 0;
                return num;
        }

        /// <summary>
        /// D值数据小数位,已改用带参数【系列】的方法
        /// </summary>
        /// <param name="D"></param>
        /// <returns></returns>
        [Obsolete]
        public static string GetDNumFormat(double D)
        {
            string dformat = "0.0";
            if(D != Convert.ToInt32(D))
                dformat = "0.00";

            return dformat;
        }

        /// <summary>
        /// D值数据小数位
        /// </summary>
        /// <param name="D"></param>
        /// <param name="series"></param>
        /// <returns></returns>
        public static string GetDNumFormat(double D,string series)
        {
            string dformat = "0.0";
            if (D != Convert.ToInt32(D))
                dformat = "0.00";

            string type = UseTempService.GetType(series);
            if (type == "solid"
                || type == "half"
                || type == "vchip"
                )
            {
                dformat = "0.00";
            }

            return dformat;
        }

        /// <summary>
        /// L值数据小数位,已改用带参数【系列】的方法
        /// </summary>
        /// <param name="L"></param>
        /// <returns></returns>
        [Obsolete]
        public static string GetLNumFormat(double L)
        {
            string dformat = "0.0";
            if (L != Convert.ToInt32(L))
                dformat = "0.00";

            return dformat;
        }

        /// <summary>
        /// L值数据小数位
        /// </summary>
        /// <param name="L"></param>
        /// <param name="series"></param>
        /// <returns></returns>
        public static string GetLNumFormat(double L, string series)
        {
            string dformat = "0.0";
            if (L != Convert.ToInt32(L))
                dformat = "0.00";

            string type = UseTempService.GetType(series);
            if (type == "solid"
                || type == "half"
                || type == "vchip"
                )
            {
                dformat = "0.00";
            }

            return dformat;
        }


            /// <summary>
            /// P值数据小数位数
            /// </summary>
            /// <param name="L"></param>
            /// <returns></returns>
            public static string GetPNumFormat(double L)
        {
            string dformat = "0.00";


            return dformat;
        }

        /// <summary>
        /// cp值数据小数位数
        /// </summary>
        /// <param name="L"></param>
        /// <returns></returns>
        public static string GetcpNumFormat(double L)
        {
            string dformat = "0.00";


            return dformat;
        }

        /// <summary>
        /// ESR/Z值数据小数位数 ，也用于其他值 ,也用于CAP DF LC等电气特性的小数位处理
        /// </summary>
        /// <param name="esrValue"></param>
        /// <returns></returns>
        public static string GetEsrNumFormat(double esrValue)
        {
            string format = "0.00";
            if (esrValue >= 1000)
                format = "0";
            else if (esrValue >= 100)
                format = "0.0";
            else if (esrValue >= 10)
                format = "0.00";
            else if (esrValue < 1)
                format = "0.000";
            else
                format = "0.00";

            return format;
        }

        /// <summary>
        /// 保留三位有效数字，ESR/Z值数据小数位数 ，也用于其他值 ,也用于CAP DF LC等电气特性的小数位处理
        /// </summary>
        /// <param name="esrValue"></param>
        /// <returns></returns>
        public static string GetEsrNumFormatRnd(double esrValue)
        {
            string format = "0.00";
            if (esrValue >= 100)
                format = "0";
            else if (esrValue >= 10)
                format = "0.0";
            else if (esrValue >= 1)
                format = "0.00";
            else if (esrValue < 1 && esrValue >0)
                format = "0.000";

            return format;
        }

        /// <summary>
        /// 保留三位有效数字，ESR/Z值数据小数位数 ，也用于其他值 ,也用于CAP DF LC等电气特性的小数位处理
        /// </summary>
        /// <param name="esrValue"></param>
        /// <returns></returns>
        public static string GetSizeNumFormatRnd(double esrValue)
        {
            string format = "0.00";
            if (esrValue >= 1)
                format = "0.00";
            else if (esrValue < 1 && esrValue > 0)
                format = "0.000";

            return format;
        }

        //
        /// <summary>
        ///   漏電流參數  toto:  公式不全 待确认
        /// 液態/半固態半液態LC公式：低壓：0.01*容量* 电压  高壓：0.03*容量* 电压+20   
        /// 固態LC公式：舊的： 0.1*容量* 电压*1.5  新的： 0.2*容量* 电压
        /// </summary>
        /// <param name="voltage"></param>
        /// <param name="series"></param>
        /// <param name="cv"></param>
        /// <param name="ua"></param>
        /// <returns></returns>
        [Obsolete]
        public static void GetLcParams(double voltage, string series, out double cv, out string ua)
        {
            cv =  0;
            ua = "+0";

            switch (series)
            {
                //固態
               case "EA":
               case "EC":
               case "EL":
               case "EH":
               case "ET":
               case "EP":
               case "PC":
               case "PL":
               case "VA":
               case "VC":
               case "VL":
               case "VH":
               case "VT":
               case "VP":
               case "PV":
               case "PH":
                    cv = 0.2;
                    ua = string.Empty;
                    break;

                //牛角
                case "LX":
                case "LXB":
                case "LXA":
                case "LZ":
                case "HZ":
                case "MZ":
                case "TZ":
                case "AZ":
                case "AU":
                    cv = 0;
                    ua = string.Empty;
                    break;

                default:
                    if (voltage < 160)
                    {
                        cv = 0.01;
                    }
                    else
                    {
                        cv = 0.03;
                        ua = "+20";
                    }
                    break;
            }
        }
    }
}
